Skip to content

Reuse Wasm locals to reduce recursive call frames - #167

Closed
vishvananda wants to merge 1 commit into
mainfrom
fix/wasm-local-reuse
Closed

vishvananda wants to merge 1 commit into
mainfrom
fix/wasm-local-reuse

Conversation

@vishvananda

@vishvananda vishvananda commented Nov 16, 2026 •

Copy link
Copy Markdown
Owner

Clang built by cppgm fails in Safari workers with RangeError: Maximum call stack size exceeded. The Wasm backend gave almost every SSA result a separate local. A recursive Clang statement visitor had 1,603 locals, which made each native call frame too large for Safari’s worker stack.

Reuse same-type Wasm locals when their live ranges do not overlap. The pass uses selected MIR and structured control-flow labels. It keeps parameter indices and zero-initialized values, follows loop edges, and has a work budget. It skips exception landing regions and leaves O0 unchanged. It does not change LowIR or x86 lowering.

The visitor now needs 17 locals. Rebuilding all 2,374 Clang objects with this change passes a 512 KiB WebKit stack limit, including both OpenLara builds and both players. The game outputs have the same hashes as before. A self-compiled native cppgm produces the same Clang objects and module as the host-built cppgm. These full Clang checks used the v0.9.1 base before rebasing this commit onto current main.

Add a PA37 maintainer regression with a recursive switch, values live across calls, loop-carried values, runtime checks and an optimized local-count bound. No student requirements change.

Validation: after rebasing onto main, PA37 (223 checks), full strict report (11,311/11,311), PA36 smoke, debug-info checks, self-host through PA5, native inception, architecture and placement audits, file and format audits, harness tests and student export validation. The WASI two-stage build matches every object and the final compiler; WASI and native compilers produce equal x86 objects at O0 and O2. Counter ABBA observations are retained locally; shared-host noise does not support a precise compile-time improvement claim.

Real Safari testing: the new Clang passes the first files that previously overflowed. An initial full run stopped at an unrelated date mismatch in the unchanged cppgm seed: exactly one byte changed from Nov 15 to Nov 16 in OpenLara’s __DATE__. The site now freezes project build dates. A full native Safari run with the corrected references is in progress. The experimental compiler package is separate from production.

@vishvananda vishvananda mentioned this pull request Nov 16, 2026
@vishvananda
vishvananda marked this pull request as ready for review November 16, 2026 00:27
@vishvananda

Copy link
Copy Markdown
Owner Author

Superseded by #168, which carries this commit unchanged with the 0.9.3 version bump.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant